'use strict';

let mongoose = require('mongoose');
const GameUserModel = mongoose.models['GameUser']


function roleDefault(gameUser){ //12月17号，添加角色，添加补丁使用角色默认为性别
    if(gameUser.ppt.role == -1){
        gameUser.ppt.role = (gameUser.sex == 1?1:2)
        return true;
    }
    return false;
}

async function repairPatch(){
    let users = await GameUserModel.find({})
    for(let i=0; i<users.length; i++){
        let res = false;
        res = roleDefault(users[i]) || res;
        res && await users[i].save();
    }
    console.log('补丁修复完成')
}

repairPatch();